class MessagesController < InnerApplicationController
  
  def index
    @messages = @project.messages.all(:order => "created_at DESC")
  end

  def show
    @message = @project.messages.find(params[:id])
  end

  def new
    @message = @project.messages.new
  end
  
  def edit
    @message = @project.messages.find(params[:id])
  end

  def create
    @message = @project.messages.new(params[:message])
    
      if @message.save
        flash[:success] = 'Message was successfully created.'
        redirect_to @project, @message
      else
        render :action => "new"
      end
  end

  # PUT /messages/1
  # PUT /messages/1.xml
  def update
    @message = @project.messages.find(params[:id])

      if @message.update_attributes(params[:message])
        flash[:success] = 'Message was successfully updated.'
        redirect_to @project, @message
      else
        render :action => "edit"
      end
  end

  # DELETE /messages/1
  # DELETE /messages/1.xml
  def destroy
    @message = Message.find(params[:id])
    @message.destroy

    respond_to do |format|
      format.html { redirect_to(messages_url) }
      format.xml  { head :ok }
    end
  end
end
